import type { FormValidator } from '@/utils/formValidators'

// 匹配字段
export type MatchField =
  | 'http.cookie'
  | 'ip.geoip.country'
  | 'ip.geoip.continent'
  | 'http.host'
  | 'ip.src'
  | 'http.referer'
  | 'http.request.method'
  | 'ssl'
  | 'http.request.full_uri'
  | 'http.request.uri.path'
  | 'http.request.uri.query'
  | 'http.request.version'
  | 'http.user_agent'
  | 'http.x_forwarded_for'

// 运算符
export type Operator =
  | 'eq'
  | 'ne'
  | 'contains'
  | 'not_contains'
  | 'in'
  | 'not_in'
  | ''

export type MultipleOperatorType = 'in' | 'contains'

export type OperatorOption = LabelValue<Operator> & { template: string }

export type RuleValue = string | number

export interface IMatchingGroup {
  uuid: string
  rules: IMatchingRule[]
}

export interface IMatchingRule {
  uuid: string
  field: string
  operator: Operator
  value: RuleValue
  custom_field: string
}

export interface IField {
  type: 'input' | 'select' | 'switch'
  options?:
    | LabelValue<string | number>[]
    | (() =>
      | Promise<LabelValue<string | number>[]>
      | LabelValue<string | number>[])
  placeholder?: string
  valueType?: 'boolean' | 'string' | 'number' | 'array'
  validator?: FormValidator | FormValidator[]
}

export interface IMatchConfig extends LabelValue<MatchField> {
  field: IField
  operatorOptions: OperatorOption[]
}
